package com.zoe.onelink.logging.biz.autoconfigure;

import com.zoe.onelink.logging.biz.aspect.BizLogAspect;
import com.zoe.onelink.logging.biz.persistent.BizLogPersistentFactory;
import com.zoe.onelink.logging.biz.persistent.IBizLogPersistent;
import com.zoe.onelink.logging.biz.persistent.impl.BizLogMessageSlf4jPersistent;
import com.zoe.onelink.logging.biz.provider.IBizLogOperatorProvider;
import com.zoe.onelink.logging.biz.provider.impl.DefaultBizLogOperatorProvider;
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.List;

/**
 * <p>标题: </p>
 * <p>描述: </p>
 * <p>版权: Copyright (c) 2021</p>
 * <p>公司: 智业软件股份有限公司</p>
 *
 * @version: 1.0
 * @author: ruansheng
 * @date: 2021-10-13
 */
@Configuration(proxyBeanMethods = false)
public class OnelinkBizLogAutoConfiguration {

    @Bean
    public IBizLogPersistent bizLogMessageSlf4jPersistent() {
        return new BizLogMessageSlf4jPersistent();
    }

    @Bean
    public BizLogPersistentFactory bizLogPersistentManager(ObjectProvider<List<IBizLogPersistent>> persistentProvider) {
        return new BizLogPersistentFactory(persistentProvider.getIfAvailable());
    }

    @Bean
    @ConditionalOnMissingBean(IBizLogOperatorProvider.class)
    public IBizLogOperatorProvider defaultBizLogOperatorProvider() {
        return new DefaultBizLogOperatorProvider();
    }

    @Bean
    public BizLogAspect bizLogAspect(BizLogPersistentFactory bizLogPersistentFactory, IBizLogOperatorProvider iBizLogOperatorProvider) {
        return new BizLogAspect(bizLogPersistentFactory, iBizLogOperatorProvider);
    }

}
